package com.msh.platform.elm.service.impl;

import com.msh.platform.bizmedia.base.util.Tools;
import com.msh.platform.elm.dao.OperLogRepository;
import com.msh.platform.elm.entity.OperLog;
import com.msh.platform.elm.service.OperLogService;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OperLogServiceImpl implements OperLogService{

    @Autowired
    private OperLogRepository operLogRepository;
    
    public List<OperLog> getOperLogByOperObj(int objId){
    	return operLogRepository.findByOperObjOrderByCreateTimeDesc(objId);
    }
    
    public OperLog findFirstByOperObj(int objId){
    	return operLogRepository.findFirstByOperObjOrderByCreateTimeDesc(objId);
    }
    
    public OperLog save(OperLog operLog) {
    	return operLogRepository.save(operLog);
    }
    
    public void addOperLog(int objId,String operType,String operDetail,int operId) {
    	Integer currTime = Tools.getCurrTime();
	    OperLog operLog = new OperLog();
		operLog.setId(UUID.randomUUID().toString());
		operLog.setOperObj(objId);
		operLog.setOperType(operType);
		operLog.setOperDetail(operDetail);
		operLog.setOperId(operId);
		operLog.setCreateTime(currTime);
		operLogRepository.save(operLog);
    }

}
